﻿@using CodeGenerator
@inherits RazorEngine.Templating.TemplateBase<CodeGenerator.Models.TemplateModels.DtoFileModel>
@@{ ViewBag.Title = "@(Model.CnName)"; Layout = "~/Views/Shared/_LayoutPlugin.cshtml"; }
@@section css{
    <style>
        .tree-btn {
            padding: 0 10px;
        }

        .img-preview {
            /* datagrid上的图片 */
            max-height: 24px;
            max-width: 64px;
        }

        .div-tree-toolbar {
            padding: 5px 10px;
            background-color: rgb(252, 252, 252);
        }

        .easyui-layout .panel-header {
            background-color: rgb(239, 239, 239);
            color: black;
            padding: 5px 15px;
            border: 1px solid rgb(197, 197, 197);
        }

            .easyui-layout .panel-header .panel-title {
                font-weight: normal;
            }

        ul.list-unstyled > li {
            margin-top: 5px;
        }

        .form-box {
            width: 200px;
        }

        .form-lb {
            display: inline-block;
            text-align: right;
            width: 100px;
        }

            .form-lb::after {
                content: ':';
            }

        #imgPreview {
            /* 编辑窗体上的图片 */
            width: auto;
            height: auto;
            max-width: 200px;
            max-height: 150px;
            /* outline: 1px solid gray; */
        }
    </style>
}

<div class="easyui-layout" data-options="fit:true">

    <div data-options="region:'center',border:false">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'center',border:false">
                <div class="dg-@(Model.Name)-toolbar">
                        <input id="search" style="width:300px" />
                    <!--
                        状态：
                        <select id="state" class="easyui-combobox" style="width:90px">
                            <option value="0">全部</option>
                            <option value="1">激活</option>
                            <option value="2">停用</option>
                        </select>
                    -->
                    <button id="btnAdd@(Model.Name)" class="btn btn-info unseen">
                        <i class="fa fa-plus"></i>新增
                    </button>
                    <button id="btnEdit@(Model.Name)" class="btn btn-info unseen">
                        <i class="fa fa-pencil"></i>编辑
                    </button>
                    <button id="btnDel@(Model.Name)" class="btn btn-info unseen">
                        <i class="fa fa-trash"></i>删除
                    </button>

                </div>
                <table id="dg"></table>
            </div>

        </div>
    </div>
</div>

@@section js{
    <script src="/Content/EasyUI/extension/jquery.edatagrid.js"></script>
    <script src="/Content/global/scripts/util.js"></script>
    <script src="~/Content/EasyUI/extension/datagrid-dnd.js"></script>
    <script>
        /** 当前操作的地址 */
        var main = {
            init: function () {
                var _this = this;
                _this.loadBase();
                _this.loadData();
            },//初始化
            search: function () {
                var _this = main;
                _this.loadData();
            },
            loadBase: function () {
                var _this = this;
                $('#search').searchbox({
                    prompt: '名称/编号',
                    searcher: _this.search
                });

                $('#btnAdd@(Model.Name)').click(_this.open@(Model.Name)AddDialog);
                $('#btnEdit@(Model.Name)').click(_this.open@(Model.Name)EditDialog);
                $('#btnDel@(Model.Name)').click(_this.del@(Model.Name));
            },
            loadData: function () {
                var _this = main;
                let filter = $('#search').searchbox('getValue');
                $('#dg').datagrid({
                    fit: true,
                    url: 'GetPageListAsync',
                    idField: 'id',
                    singleSelect: true,
                    checkOnSelect: false,
                    selectOnCheck: false,
                    pagination: true,
                    pageSize: 50,
                    pageList: [10, 20, 50, 100],
                    toolbar: '.dg-@(Model.Name)-toolbar',
                    queryParams: {
                        Filter: filter,                        
                    },
                    fitColumns:true,
                    columns: [[
                      @foreach (var item in Model.ClassPropertys)
                      {                          
                          if (!item.IsList) { continue; }
                        @:{ field: '@item.Name.FirstCharToLower()', title: '@item.CnName', align: 'center', width: 100 },
                      }
                    ]],
                    onLoadSuccess: function () {
                        $(this).datagrid('clearSelections');
                        $(this).datagrid('clearChecked');
                    },
                    onDblClickRow: function () {
                        _this.open@(Model.Name)EditDialog();
                    },
                    onSelect: function () {
                        $('#dg-stock').datagrid('reload');
                    }
                })
            },
            //事件组
            open@(Model.Name)AddDialog: function () {
                parent.layerOpen("添加", '/@(Model.Name)/@(Model.Name)Edit', function () {
                    $('#dg').datagrid('reload');
                }, 690, 222, { act: 1 ,baseWindow:window})
            },
            open@(Model.Name)EditDialog: function () {

                let selectedRow =$('#dg').datagrid('getSelected');
                if (!selectedRow) {
                    $('#dg').datagrid('showTip')
                    return;
                }

               parent.layerOpen("编辑", '/@(Model.Name)/@(Model.Name)Edit', function () {
                    $('#dg').datagrid('reload');
                }, 690, 222, { act: 2,baseWindow:window })
            },
            del@(Model.Name): function () {
                let rows = $('#dg').datagrid('getChecked');
                if (rows.length===0) {
                    parent.layer.msg("请先勾选要删除的行", { icon: 5 });
                    return;
                }
                $.messager.confirm('提示', '确定要删除该终端吗？', function (b) {
                    if (!b) return;
                    var idList = rows.map(function (o) { return o.id });
                    $.messager.progress();
                    $.post('/@(Model.Name)/Delete',
                        { input: idList }
                    ).done(function (re) {
                        if (re.success) {
                            parent.layer.msg("操作成功", { icon: 6 });
                            $("#dg").datagrid('reload');;
                        } else {
                            $.messager.alert('提示', re.message);
                        }
                    }).always(function () {
                        $.messager.progress('close');
                    });
                });
            },
            updateStatus: function () {
                var row = $("#dg").datagrid("getSelected");
                if (row != null) {
                    $.post('UpdateStatus',
                        { Id: row.id }
                    ).done(function (re) {
                        if (re.success) {
                            $.messager.info('操作成功');
                            $("#dg").datagrid('reload');;
                        } else {
                            $.messager.alert('提示', re.message);
                        }
                    });
                }
            },
        };
        $(function () {
            main.init();
        });

    </script> }